import { Context } from "egg";
import { BusinessController } from "../../mvc";
import ApplicationService from "../../service/application";

/**
 * @Controller 应用管理 ApplicationsController
 */
export default class ApplicationController extends BusinessController<ApplicationService> implements RestfulController {
  constructor(ctx: Context) {
    super(ctx);
    this.business = ctx.service.application;
  }

  /**
   * @summary 创建应用
   * @description 创建应用
   * @router POST /api/v1/applications
   * @request body ApplicationModel
   * @response 200 BaseResModel
   */
  async create() {
    const resp = await this.business.create(this.ctx.request.body);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 删除应用
   * @description 删除应用
   * @router DELETE /api/v1/applications/{id}
   * @request path string *id 应用id
   * @response 200 BaseResModel
   */
  async destroy() {
    const { ctx } = this;
    const resp = await this.business.destroy(ctx.params.id);
    ctx.body = resp.body;
    ctx.status = resp.status;
  }

  /**
   * @summary 修改应用
   * @description 修改应用
   * @router PUT /api/v1/applications/{id}
   * @request path string *id 应用id
   * @response 200 BaseResModel
   */
  async update() {
    const resp = await this.business.update(this.ctx.params.id, this.ctx.request.body);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 查询应用列表
   * @description 查询应用列表
   * @router GET /api/v1/applications
   * @request query string appName 应用名称
   * @request query string pltId 流媒体平台ID
   * @response 200 BaseResModel
   */
  async index() {
    const { ctx } = this;
    const resp = await this.business.index(ctx.query);
    ctx.body = resp.body;
    ctx.status = resp.status;
  }

  /**
   * @summary 查询应用明细
   * @description 查询应用明细
   * @router GET /api/v1/applications/{id}
   * @request path string *id 应用id
   * @response 200 BaseResModel
   */
  async show() {
    const resp = await this.business.show(this.ctx.params.id);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 查询应用分页列表
   * @description 查询应用分页列表
   * @router GET /api/v1/page/applications
   * @request query integer *current 当前页
   * @request query integer *pageSize 每页条数
   * @request query string appName 应用名称
   * @request query string pltId 流媒体平台ID
   * @response 200 BaseResModel
   */
  async page() {
    const resp = await this.business.page(this.ctx.query);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }
}
